<template>
  <!-- <div> -->
  <el-dialog title="标注编辑" :visible="dialogFormVisible" :modal="false" @close="editTooltilpClose" class="edit-tooltilp" top='10vh'>
    <el-form :model="form">
      <el-form-item label="标注名称" :label-width="formLabelWidth">
        <el-input v-model="form.name" autocomplete="off" :clearable="true"></el-input>
      </el-form-item>
      <el-form-item label="标注描述" :label-width="formLabelWidth">
        <!-- :autosize="{ minRows: 2, maxRows: 4}" -->
        <el-input type="textarea" v-model="form.desc" :autosize="{ minRows: 4, maxRows: 6}" resize='none'></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="danger" @click=markerDel>删 除</el-button>
      <el-button @click=cancel>取 消</el-button>
      <el-button type="primary" @click=confirm>确 定</el-button>
    </div>
  </el-dialog>
  <!-- </div> -->
</template>
<script>
  export default {
    data() {
      return {
        form: {
          name: this.markerFormName,
          desc: this.markerFormDesc
        },
        formLabelWidth: '80px'
      }
    },
    props: {
      dialogFormVisible: {
        type: Boolean,
        default: false
      },
      markerFormDesc: {
        type: String,
        default: ''
      },
      markerFormName: {
        type: String,
        default: ''
      }
    },
    methods: {
      editTooltilpClose() {
        this.$emit('editTooltilpClose')
      },
      cancel() {
        if (this.markerFormName || this.markerFormDesc) {
          this.confirm()
        } else {
          this.form = {
            name: '',
            desc: ''
          }
          this.editTooltilpClose()
        }
      },
      markerDel() {
        this.$emit('markerDel')
      },
      confirm() {
        const name = this.form.name
        const desc = this.form.desc
        this.$emit('confirm', name, desc)
        this.form = {
          name: '',
          desc: ''
        }
      }
    },
    watch: {
      dialogFormVisible(newVal, oldVal) {
        if (newVal) {
          this.form = {
            name: this.markerFormName,
            desc: this.markerFormDesc
          }
        }
      }
    }
  }
</script>
<style lang="less">
  .edit-tooltilp {
    .el-dialog {
      width: 460px;

      .el-form {
        width: 400px;

        .el-input {
          width: 320px;
        }
      }

      //   position: absolute;
      //   margin: 0;
    }
  }
</style>